<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row>
          <a-col :xs="24" :sm="12">
           <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol"  label="原车装备">
              <a-input
                placeholder="请输入原车装备"
                v-decorator="['name', { rules: [{ required: true, message: '请输入原车装备' }] }]"
              />
              <!-- <a-checkbox-group @change="onChange" v-model="defaultValue">
                <a-row>
                  <a-col :span="6">
                    <a-checkbox value="空调">空调</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="点烟器">点烟器</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="安全气囊">安全气囊</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="电动天窗">电动天窗</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="行车记录仪">行车记录仪</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="电动遥控门窗">电动遥控门窗</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="ABS防抱死系统">ABS防抱死系统</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="冰箱">冰箱</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="烟灰缸">烟灰缸</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="车载电视">车载电视</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="电子手刹">电子手刹</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="超速报警器">超速报警器</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="自动巡航系统">自动巡航系统</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="防盗报警装置">防盗报警装置</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="备胎">备胎</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="中控锁">中控锁</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="电子座椅">电子座椅</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="倒车雷达">倒车雷达</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="无钥匙启动">无钥匙启动</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="GPS定位系统">GPS定位系统</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="胎压监测装置">胎压监测装置</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="音响">音响</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="多媒体">多媒体</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="儿童座椅">儿童座椅</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="自动驻车">自动驻车</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="电动后备箱">电动后备箱</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="气囊减震座椅">气囊减震座椅</a-checkbox>
                  </a-col>
                  <a-col :span="6">
                    <a-checkbox value="多功能方向盘">多功能方向盘</a-checkbox>
                  </a-col>
                </a-row>
              </a-checkbox-group> -->
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import pick from 'lodash.pick'
import moment from 'moment'

export default {
  name: 'EquipmentModel',
  data() {
    return {
      title: '原车装备设置',
      visible: false,
      model: {},
      saleSource: [],
      SaleInfosLike: [],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },

      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {},
      url: {
        add: '/sale/cxmSaleBaseInfo/addBaseInfo',
        edit: '/sale/cxmSaleBaseInfo/editBaseInfo',
      },
      showDing: false,
      showEnterpriseUscc: false,
      equipment: [],
      defaultValue: []
    }
  },
  created() {
  },
  methods: {
    changeDepositNotes(val) {
      if (val == '不可退') {
        this.showDing = true
      } else {
        this.showDing = false
      }
    },
    add(record) {
      console.log(record);
      this.edit(record)
    },
    edit(record) {
      this.form.resetFields()
      this.model = Object.assign({}, record)
      console.log(this.model);
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue({
          name: this.model.name
        })
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'post'
          }
          let formData = Object.assign(this.model, values, { dataType: 7 })
          //时间格式化
          //formData.createTime = formData.createTime ? formData.createTime.format('YYYY-MM-DD HH:mm:ss') : null
          /* formData.name = this.equipment.join(','); */
          httpAction(httpurl, formData, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        }
      })
    },
    handleCancel() {
      this.close()
    },
    /* onChange(checkedValues) {
      console.log('checked = ', checkedValues);
      this.equipment = checkedValues
    }, */
  },
}
</script>

<style lang="less" scoped>
</style>